package com.fzk.blog.utils;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;

import java.math.BigInteger;
import java.util.Random;

/**
 * @author fzk
 * @date 2021-07-15 21:57
 */
public class MyIdUtil {
    public static BigInteger getSnowId() {
        //参数1为终端ID：本次项目使用随机数做为终端id
        //参数2为数据中心ID：本次项目使用时间作为数据中心id
        int i = new Random().nextInt(32);
        String time_s = MyDateTimeUtil.getNowDateOrTime("ss");
        String time_m = MyDateTimeUtil.getNowDateOrTime("mm");
        Snowflake snowflake = IdUtil.getSnowflake(
                i , (Long.parseLong(time_s)  +Long.parseLong(time_m)) % 32);
        long id = snowflake.nextId();
        return BigInteger.valueOf(id);
    }
}
